// Copyright(C) Japan Android Group Gunma
// LGPL License
// Writers Rabbit-U

package jp.android_group.gunma.gunma_app_lib;

import jp.android_group.gunma.gunma_app_lib.LocationGetter.GetLocationListener;
import jp.android_group.gunma.gunma_app_lib.LocationGetter.LocationInfo;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class CityActivity extends Activity {

	LocationGetter m_locgetter = new LocationGetter();
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.city);
		
		m_locgetter.startGetLocation(this, new GetLocationListener() {

			public void onError() {
				// Under construction.
			}

			public void onGetLocation(LocationInfo info) {
				CityActivity.this.onGetLocation(info);
			}
			
		});
		
		{
			Button v = (Button)findViewById(R.id.ButtonTwitter);
			v.setOnClickListener(new OnClickListener() {

				public void onClick(View v) {
					Intent intent = new Intent();
					intent.setClass(CityActivity.this, TwitterActivity.class);
					intent.putExtra("city", m_info.m_city);
					startActivity(intent);
				}
				
			});
		}

		{
			Button v = (Button)findViewById(R.id.buttonRSS);
			v.setOnClickListener(new OnClickListener() {

				public void onClick(View v) {
					Intent intent = new Intent();
					intent.setClass(CityActivity.this, RSSActivity.class);
					intent.putExtra("city", m_info.m_city);
					startActivity(intent);
				}
				
			});
		}

	}
	
	LocationInfo m_info;
	
	void onGetLocation(LocationInfo info) {

		m_info = info;
		
		if( m_info.m_prefecture.equals("群馬県") ) {
		
			{
				Button v = (Button)findViewById(R.id.ButtonTwitter);
				v.setEnabled(true);
			}
	
			{
				Button v = (Button)findViewById(R.id.buttonRSS);
				v.setEnabled(true);
			}
	
			{
				TextView v = (TextView)findViewById(R.id.textViewName);
				v.setText(info.m_city);
			}
			
		} else {
			
			TextView v = (TextView)findViewById(R.id.textViewName);
			v.setText(info.m_prefecture);
			
		}

	}

}
